# coding=utf-8

import os
from app import create_app, db
from app.models import (User, Group, \
                        Duty, TempText, \
                        RichText, Picture, \
                        BandWidth, OPEvent, \
                        DailyInfo, EngineRoom, \
                        Email, EmailStatus)
from flask_script import Manager, Shell
from flask_migrate import Migrate, MigrateCommand


config_name = os.environ.get("FLASK_CONFIG") or "default"
app = create_app(config_name)

if config_name in ['default', 'development']:
    db.create_all(app=app)
#

manager = Manager(app)
migrate = Migrate(app, db)

def make_shell_context():
    return dict(app=app, db=db, \
                User=User, Group=Group, \
                Duty=Duty, TempText=TempText, \
                RichText=RichText, Picture=Picture, \
                BandWidth=BandWidth, OPEvent=OPEvent, \
                DailyInfo=DailyInfo, \
                EngineRoom=EngineRoom, \
                Email=Email, \
                EmailStatus=EmailStatus,)


manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command("db", MigrateCommand)

if __name__ == "__main__":
    manager.run()